﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Dapper;
using DapperExtensions;
using DapperWrapper;
using ZLWeb.WebApiEntity.CRM;
using ZLWeb.WebApiEntityBase;
using ZLWeb.WebApiRepository.InterFace;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.Core.CommonRepository;
using ZilLion.Service.Core.WechatService.Domain;

namespace ZLWeb.WebApiRepository
{
    public class CRMSettingRepository : CRMSqlServerRespository<KzSettingModel>, ICRMSettingRepository
    {
        public CRMSettingRepository() : base(new WechatServiceContext())
        {
        }

        public KzSettingModelResponse GetKzSettingModel()
        {
            KzSettingModel reCard = new KzSettingModel();
            DynamicParameters p = CreateDynamicParameters();
            List<KzSettingModel> items = ExecuteProcWithTemptable(reCard, "pr_jltycrmkykzt_query", "#jltycrmkykzt", false, p).ToList();
            KzSettingModelResponse Response=new KzSettingModelResponse() { KzSettings = items };
            return Response;
        }

        public ZklbSettingResponse GetZklbSettingModel()
        {
            ZklbSettingModel reCard = new ZklbSettingModel();
            DynamicParameters p = CreateDynamicParameters();
            List<ZklbSettingModel> items = ExecuteProcWithTemptable(reCard, "pr_jltycrmkyzklbt_query", "#jltycrmkyzklbt", false, p).ToList();
            ZklbSettingResponse Response = new ZklbSettingResponse() { ZklbSettings = items };
            return Response;
        }

        public KzSettingModel SaveKzSettingModel(KzSettingModel KzSetting)
        {
            DynamicParameters p = CreateDynamicParameters();
            KzSettingModel item = ExecuteProcWithTemptable(KzSetting, "pr_jltycrmkykzt_save", "#jltycrmkykzt", true, p).FirstOrDefault();
            return ReturnResponseResultInfo<KzSettingModel>(p) ?? item ?? new KzSettingModel();
        }

        public ZklbSettingModel SaveZklbSettingModel(ZklbSettingModel ZklbSetting)
        {
            DynamicParameters p = CreateDynamicParameters();
            ZklbSettingModel item = ExecuteProcWithTemptable(ZklbSetting, "pr_jltycrmkyzklbt_save", "#jltycrmkyzklbt", true, p).FirstOrDefault();
            return ReturnResponseResultInfo<ZklbSettingModel>(p) ?? item ?? new ZklbSettingModel();
         }

    }
}
